package com.atguigu.test;

import com.atguigu.bean.Person;
import com.atguigu.config.MainConfigOfPropertyValue;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;

public class IOCTest_PropertyValue {

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfigOfPropertyValue.class);

    @Test
    public void test1(){
        // printBeans(context);
        // System.out.println("---------------");
        System.out.println(context.getBean(Person.class));

        // 所有的配置文件中的k/v值都存储在容器运行过程中的环境变量里面
        // ConfigurableEnvironment environment = context.getEnvironment();
        //
        // String property = environment.getProperty("person.nickName");
        // System.out.println(property);
    }

    private void printBeans(ApplicationContext context) {
        String[] beanDefinitionNames = context.getBeanDefinitionNames();
        for (String beanName : beanDefinitionNames) {
            System.out.println(beanName);
        }
    }

}
